import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { SongModule } from './song/song.module';
import { AuthModule } from './auth/auth.module';
import { ConfigModule } from './config/config.module';
import { ConfigService } from '@nestjs/config';
import { PlaylistModule } from './playlist/playlist.module';
import { MyMusicModule } from './my-music/my-music.module';
import { MusicDirectoryModule } from './music-directory/music-directory.module';
import { CategoryModule } from './category/category.module';
import { SingerModule } from './singer/singer.module';
import { AlbumModule } from './album/album.module';
import { AdminModule } from './admin/admin.module';

@Module({
  imports: [
    ConfigModule,
    // TypeORM配置
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        type: 'mysql',
        host: configService.get('DB_HOST', 'localhost'),
        port: parseInt(configService.get('DB_PORT', '3306')),
        username: configService.get('DB_USERNAME', 'root'),
        password: configService.get('DB_PASSWORD', ''),
        database: configService.get('DB_DATABASE', 'music_website'),
        entities: [__dirname + '/**/*.entity{.ts,.js}'],
        synchronize: true, // 在开发环境中可以使用synchronize，生产环境应该使用migration
        autoLoadEntities: true,
      }),
      inject: [ConfigService],
    }),
    UserModule,
    SongModule,
    AuthModule,
    PlaylistModule,
    MyMusicModule,
    MusicDirectoryModule,
    CategoryModule,
    SingerModule,
    AlbumModule,
    AdminModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
